package com.atguigu.lease.admin.controller;

import com.atguigu.lease.admin.service.LabelInfoService;
import com.atguigu.lease.enums.ItemType;
import com.atguigu.lease.pojo.LabelInfo;
import com.atguigu.lease.result.Result;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/label")
@RestController
public class LabelInfoController {
    @Autowired
    private LabelInfoService labelInfoService;
    
    @GetMapping("/list")
    public Result<List<LabelInfo>> list(@RequestParam(value = "type",required = false) ItemType type) {
        List<LabelInfo> list = labelInfoService.list(Wrappers.lambdaQuery(LabelInfo.class).eq(type != null, LabelInfo::getType, type));
        return Result.success(list);
    }

    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody LabelInfo labelInfo) {
        labelInfoService.saveOrUpdate(labelInfo);
        return Result.success(null);
    }

    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam(value = "id") Long id) {
        labelInfoService.removeById(id);
        return Result.success(null);
    }
}
